﻿using System.Collections.Generic;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using Freedom.Framework.Mvc.Routes;

namespace Freedom.JqxGrid
{
    public class RouteProvider : IRouteProvider
    {
        private const string Prefix = "JqxGrid";
        private readonly string _moduleNameSpace;
        
        public RouteProvider()
        {
            _moduleNameSpace = GetType().Namespace;
        }

        #region IRouteProvider Members

        public IEnumerable<Route> GetRoutes()
        {
            return new[]
                {
                    new Route(
                        Prefix + "/{controller}/{action}/{id}",
                        new RouteValueDictionary(new { Area = _moduleNameSpace, controller = "Home", action = "Index", id = UrlParameter.Optional}),
                        new MvcRouteHandler())
                };
        }

        public void GetApiRoutes(HttpRouteCollection routes)
        {
            routes.Add(
                Prefix + ".DefaultApi", 
                routes.CreateRoute(routeTemplate: "JqxGrid/api/{controller}/{id}", defaults: new {Area = _moduleNameSpace, id = RouteParameter.Optional}, constraints: null)
                );
        }


        public void GetRoutes(RouteCollection routes)
        {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        #endregion
    }
}